package com.yinhe.exercise.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yinhe.exercise.domain.YhExercise;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;

import com.yinhe.exercise.service.IYhExerciseService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 * 
 * @author yinhe
 * @date 2023-02-06
 */
@RestController
@RequestMapping("/system/exercise")
public class YhExerciseController extends BaseController
{
    @Autowired
    private IYhExerciseService yhExerciseService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhExercise yhExercise)
    {
        startPage();
        List<YhExercise> list = yhExerciseService.selectYhExerciseList(yhExercise);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhExercise yhExercise)
    {
        List<YhExercise> list = yhExerciseService.selectYhExerciseList(yhExercise);
        ExcelUtil<YhExercise> util = new ExcelUtil<YhExercise>(YhExercise.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhExerciseService.selectYhExerciseById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhExercise yhExercise)
    {
        return toAjax(yhExerciseService.insertYhExercise(yhExercise));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhExercise yhExercise)
    {
        return toAjax(yhExerciseService.updateYhExercise(yhExercise));
    }


    /**
     * 导入
     */
    @Log(title = "合同台账", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:exercise:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YhExercise> util = new ExcelUtil<YhExercise>(YhExercise.class);
        List<YhExercise> contractList = util.importExcel(file.getInputStream());
        String message = yhExerciseService.importContract(contractList, updateSupport);
        return AjaxResult.success(message);
    }
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YhExercise> util = new ExcelUtil<YhExercise>(YhExercise.class);
        util.importTemplateExcel(response, "导入数据");
    }




    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhExerciseService.deleteYhExerciseByIds(ids));
    }
}
